#include "GlobalManage.h"
#include <QFile>

/*
 * 全局API类，公共API接口
 *
 */
static GlobalManage *m_pInstance = NULL;

GlobalManage::GlobalManage(QObject *parent) : QObject(parent)
{

}

GlobalManage::~GlobalManage()
{
    m_pInstance = NULL;
}

GlobalManage *GlobalManage::instance()
{
    if(NULL == m_pInstance)
    {
        m_pInstance = new GlobalManage();
    }

    return m_pInstance;
}

bool GlobalManage::FileIsExist(QString strFile)
{
    QFile tempFile(strFile);
    return tempFile.exists();
}

bool GlobalManage::FormatStringWithTwoDecimal(QString *text)
{
    int i=0,j=0;
    QString qstr;
    QString strTemp;

    qstr = *text;
    if(qstr == tr(""))
    {
        return false;
    }

    strTemp = qstr;
    for( i=0; i<qstr.length(); ++i )
    {
        if( qstr.mid(i, 1) == "." )
        {
            j++;
            if( i == qstr.length()-1 )
            {
               strTemp = strTemp+"00";
            }
            else if( i == qstr.length()-2 )
            {
               strTemp = strTemp+"0";
            }

            if(0 == i)
            {
                strTemp = "0"+strTemp;
            }
            break;
        }
    }

    if( j == 0 && qstr.length() != 0 )
    {
        strTemp = strTemp + ".00";
    }

    qstr = strTemp;
    if((qstr.length() > 1) && (qstr.mid(0, 1) == "0") && (qstr.mid(1, 1) != "."))
    {
        strTemp = qstr.mid(1, (qstr.length() - 1));
    }

    *text  = strTemp;
}

ELoginUserType GlobalManage::GetLoginUserType()
{
//    //普通用户
//    Elut_Normaler = 1,
//    //管理员
//    Elut_Admin = 2,
//    //用服
//    Elut_Service = 3,
//    //开发
//    Elut_Developer = 4
    return Elut_Normaler;
}


